package com.studentportalen;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class CoursesActivity extends ListActivity {
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_courses);
        
        //Get data from db
        DBHelper db = Global.getDBHelper();
        Cursor c = db.getAllCourses();

        // create an array to specify which fields we want to display
        String[] from = new String[]{"name"};
        // create an array of the display item we want to bind our data to
        int[] to = new int[]{android.R.id.text1};
        
        SimpleCursorAdapter adapter =
                new SimpleCursorAdapter(this, R.layout.list_item_courses, c, from, to );
        
        //put data into list adapter
        setListAdapter(adapter);
    }
    
    
    public void onListItemClick(ListView parent, View v, int position, long id) {
    	//TODO: skicka med n�n data h�r s� vi vet vilken kurs man tryckt p� 
    	Intent intent = new Intent(CoursesActivity.this, CoursesDetailsActivity.class);
    	intent.putExtra("id", (int)id);
    	startActivity(intent);
	}
    
}
